<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<script type="text/javascript" language="javascript">
    var combothajaranStoredbs = createStore(false, 'mcombothajaranStoredbs',['id_th_ajaran','tahun_ajaran'],'<?php echo base_url(); ?>' + 'tahunajaran/get_rows_combo');
    var combo_bulandbs_Store=createArrayStore2( ['num', 'name'],bulan_data);
    var allsiswaStoredbs = createStore(false, 'mallsiswaStoredbs',['nis','nama','kd_kelas','kelas'],'<?php echo base_url(); ?>' + 'datasiswa/get_rows_all');
    var comboKelasStoredbs = createStore(false, 'mcomboKelasStore_d', ['kd_kelas','keterangan'], '<?php echo base_url(); ?>' + 'masterkelas/get_rows_combo');
    //==========================================================================================
    var twinsiswadbsStore = createStore(false, 'mtwinsiswadbsStore',['nis','nama','kd_kelas','kelas'],'<?php echo base_url(); ?>' + 'datasiswa/get_rows_twin');
    defineTwinSiswa_windows('Windowfindsiswadbs', 'Windowfindsiswadbs_id', twinsiswadbsStore, function(){			
        var sm = this.getSelectionModel();
        var sel = sm.getSelection();
        //                console.log('doublekil');
        if (sel.length > 0) {	
            Ext.getCmp('dbs_nis').setValue(sel[0].get('nis'));  
            Ext.getCmp('dbs_nama').setValue(sel[0].get('nama'));  
            Ext.getCmp('dbs_kd_kelas').setValue(sel[0].get('kd_kelas'));  
            Ext.getCmp('Windowfindsiswadbs_id').close();            
        }
    });
    
    //===================
    
    
    
    defineTabFormDynamis(
    {
        name:'MyTabDaftarBiayaSiswa',
        xtype:'TabDaftarBiayaSiswa',
        alias:'widget.TabDaftarBiayaSiswa',
        title:'Daftar Biaya Siswa',
        id:'tab15'
        ,items:[
            {
                xtype: 'form',
                autoShow: true,
                id: 'paneldbs',
                region: 'north',
                margins: '5 5 5 5',
                layout: 'column',                
                items:[
                    {
                        xtype: 'form',
                        columnWidth: .4,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 85,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype:'combo',
                                afterLabelTextTpl: required_css,
                                name: 'id_th_ajaran',
                                id: 'dbs_id_th_ajaran',
                                fieldLabel: 'Tahun Ajaran',                                    
                                //                    labelWidth: 80,
                                emptyText: 'Tahun Ajaran'
                                ,mode:'local',
                                store: combothajaranStoredbs,
                                valueField: 'id_th_ajaran',
                                displayField: 'tahun_ajaran',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: false,
                                editable: false  ,
                                hiddenName:'id_th_ajaran'
                                ,listeners:{
                                    select:function(cmb,rec){
                                        console.log(rec[0].get('tahun_ajaran'));
                                    }
                                }
                            },{
                                xtype: 'combo',                        
                                name:'kd_kelas',
                                //                                    tooltip: 'Field tidak boleh kosong',
                                //                                    afterLabelTextTpl: required_css,
                                fieldLabel: 'Kelas',                        
                                id: 'dbs_kd_kelas',
                                mode:'local',
                                store: comboKelasStoredbs,
                                valueField: 'kd_kelas',
                                displayField: 'keterangan',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                //                                    allowBlank: false,
                                editable: true,                                    
                                hiddenName: 'kd_kelas',
                                margins: '0 0 0 5',
                                emptyText: 'Pilih Kelas'
                                //                                    listeners:{
                                //                                        select:function(cb){
                                //                                            if(cb.getValue()){
                                //                                                var store=Ext.getCmp('griddaftarsiswa').getStore();
                                //                                                store.getProxy().setExtraParam("kelas",cb.getValue());
                                //                                                store.reload(); 
                                //                                            }
                                //                                        }
                                //                                    }
                            }      
                            
                        ]
                    }
                    ,{
                        xtype: 'form',
                        columnWidth: .4,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 85,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype: 'twincombo'
                                ,name: 'nis'
                                ,fieldLabel: 'NIS',
//                                tooltip: 'Field tidak boleh kosong',
//                                afterLabelTextTpl: required_css,
                                id:'dbs_nis',
                                store:twinsiswadbsStore,
                                menu:'Windowfindsiswadbs',
                                enableKeyEvents:true,
                                emptyText:'Entry / Pilih Siswa',
                                allowBlank:true
                                ,listeners:{
                                    keyup: function(f,e,opt) { 
                                        if (e.getKey()==113){
                                            f.onTrigger1Click();
                                        }          
                                        if (e.getKey()==13){
                                            if(f.getValue().length>0){
                                                var rec=  findNis(f.getValue(), allsiswaStoredbs);                                                
                                                if(rec){
                                                    Ext.getCmp('dbs_nama').setValue(rec.get('nama'));
                                                    Ext.getCmp('dbs_kd_kelas').setValue(rec.get('kd_kelas'));
                                                    //                                                    Ext.getCmp('sim_th_ajaran').focus();
                                                }else{
                                                    set_message(2,'Data Siswa Tidak Terdaftar !!!');
                                                    f.setValue('');
                                                }
                                            };
                                        }
                                    }
                                }
                                //                    ,readOnly:true                                    
                            },{
                                name: 'nama',
                                id: 'dbs_nama',
                                fieldLabel: 'Nama Siswa',
                                maxLength:50,
                                emptyText: 'Nama Siswa',
                                allowBlank: true
                                ,readOnly:true                    
                            }
                        ]
                    }
                ],
                bbar:[
                    {
                        xtype: 'button',
                        id:'btn_cetak',
                        text: 'Cetak',
                        iconCls: 'icon-preview_report',
                        enableToggle: true,
                        onClick: function(btn){
                            var urlprint=get_seturl_dbs();
                            if(!urlprint){
                                set_message(1, 'Tahun Ajaran Belum Dipilih !!!');
                                return;
                            }
                            getComp('btn_cetak').toggle();
                            getComp('btn_cetakpotongan').toggle(false);
                            to_print('printdbs', urlprint);
                        }
                    }
                    ,'-'
                    ,{
                        xtype: 'button',
                        id:'btn_cetakpotongan',
                        text: 'Cetak Potongan',
                        iconCls: 'icon-preview_report',
                        enableToggle: true,
                        onClick: function(){
                            getComp('btn_cetak').toggle(false);
                            getComp('btn_cetakpotongan').toggle();                            
                            url_print_potongan='';
                            var winpotdbs=Ext.create('winnisthbl');
                            winpotdbs.on('close',function(){                                
                                if(!url_print_potongan){
                                    getComp('btn_cetakpotongan').toggle(false);   
                                }
                            });
                            getComp('base_kd_kelas').setVisible(false);
                            getComp('btn_base_proses_id').on('click',function(){
                                if(!getComp('base_tahun').getValue() || !getComp('base_bulan').getValue()){
                                    set_message(1, 'ThBl Periode Tidak Valid!!');
                                    return;
                                }else{
                                    var nis=getComp('base_nis').getValue();
                                    var thbl=setThbl(Ext.getCmp('base_tahun').getValue(), Ext.getCmp('base_bulan').getValue());;
                                    url_print_potongan = get_url_potongan(nis, thbl);
                                    to_print('printdbs', url_print_potongan);
                                    getComp('winnisthbl_id').close();
                                }
                                
                            });
                            winpotdbs.show();
                        }
                    }
                ]
                    
                
            },
            {
                
                xtype: 'panel',
                autoShow: true,
                autoScroll: true,
                enableToggle: true,
                title:'Print Preview PDF',
                id: 'paneldbs_c',
                region: 'center',
                margins: '5 5 5 5',
                layout: 'fit',                
                tools: [{
                        type: 'maximize',
                        tooltip: 'Maximize Print Preview' 
                        ,listeners:{
                            click:function()   {
                                var urlprint='';
                                if(!getComp('btn_cetak').pressed && !getComp('btn_cetakpotongan').pressed){
                                    return;
                                }
                                if(getComp('btn_cetak').pressed){
                                    urlprint=get_seturl_dbs();
                                    if(!urlprint){
                                        set_message(1, 'Tahun Ajaran Belum Dipilih !!!');
                                        return;
                                    }
                                }
                                if(getComp('btn_cetakpotongan').pressed){
                                    urlprint= url_print_potongan;
                                    if(!urlprint){
                                        set_message(1, 'Parameter Pilihan Belum Tidak Valid !!!');
                                        return;
                                    }
                                    
                                }
                                
                                var winprintdbs=Ext.create('winprint2');
                                winprintdbs.maximize();
                                to_print('printoutpdf2', urlprint);                         
                            }
                        }
                    }],
                html:'<iframe style="width:100%;height:100%;" id="printdbs" src=""></iframe>'
                
            }
        ]
    },     
    function(){            
        allsiswaStoredbs.load();
    }
);
    var url_print_potongan='';
    function get_url_potongan(nis,thbl){
        var urlprint='base_report/potongan_print?thbl=' + thbl ;
        if(nis){
            urlprint +='&nis=' + nis;
        }
        return urlprint;
    }
    function get_seturl_dbs(){
        var thajaran=getComp('dbs_id_th_ajaran').getValue();
        var kdkelas=getComp('dbs_kd_kelas').getValue();
        var nis=getComp('dbs_nis').getValue();
        var urlprint='base_report/biaya_siswa_print?thajaran=' ;
        
        if(!thajaran){
            
            urlprint='';
        }else{
            urlprint += thajaran;
        }
        if(kdkelas){
            urlprint += '&kelas='+kdkelas;
        }
        if(nis){
            urlprint += '&nis='+nis;
        }
        readLog(urlprint);
        return urlprint;
    }
</script>
